import http from './http'
import { CategoryModel, CategoryQuery } from './model'

export const getByIdApi = (id: string | undefined) => http.get<CategoryModel>(`/api/category/${id}`)

export const loadListApi = (query: CategoryQuery) =>
  http.get<CategoryModel[]>('/api/category/tree', { params: query })

export const addApi = (param: CategoryModel) => http.post<CategoryModel[]>('/api/category', param)

export const updateApi = (param: CategoryModel) => http.put<CategoryModel[]>('/api/category', param)

export const deleteApi = (ids: string[], cascade?: Boolean) =>
  http.delete<CategoryModel[]>('/api/category', { data: ids, params: { cascade: cascade } })
